<template>
    <view class="wo-page u-padding-20">
        <view class="wo-page-body u-padding-20">
            <u-cell-group class="u-margin-bottom-20"><u-cell-item v-for="(field_v, field_k) in fieldConfig" :key="field_k" :title="field_v.label" :value="field_v.field_result"></u-cell-item></u-cell-group>
            <u-button type="primary" shape="circle" @click="$u.route('pages/index')">返回首页</u-button>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            dataDetail: {},
            // 字段配置
            fieldConfig: {
                name: {
                    field: 'name',
                    label: '接种点名称',
                    field_result: '',
                    initFunc(viewModel) {
                        if (viewModel.dataDetail[this.field]) {
                            this.field_result = viewModel.dataDetail[this.field];
                        }
                    }
                },
                area_id: {
                    field: 'area_id',
                    label: '所属区域',
                    field_result: '',
                    async initFunc(viewModel) {
                        let areaData = await viewModel.$u.api.areaSelectData();
                        if (!areaData) {
                            return false;
                        }
                        if (viewModel.dataDetail[this.field]) {
                            for (let index in areaData) {
                                if (areaData[index].value == viewModel.dataDetail[this.field]) {
                                    this.field_result = areaData[index].label;
                                    break;
                                }
                                for (let _index in areaData[index].children) {
                                    if (areaData[index].children[_index].value == viewModel.dataDetail[this.field]) {
                                        this.field_result = areaData[index].label + ',' + areaData[index].children[_index].label;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                },
                address: {
                    field: 'address',
                    label: '接种点地址',
                    field_result: '',
                    initFunc(viewModel) {
                        if (viewModel.dataDetail[this.field]) {
                            this.field_result = viewModel.dataDetail[this.field];
                        }
                    }
                },
            }
        };
    },
    methods: {
        // 页面初始化
        async initPageFunc(option) {
            let id = option.id || 0;
            if (!id) {
                return false;
            }
            let dataDetail = await this.$u.api.hospitalDetail({
                id: id
            });
            if (!dataDetail) {
                return false;
            }
            this.dataDetail = dataDetail;
            for (let field in this.fieldConfig) {
                if (this.fieldConfig[field].hasOwnProperty('initFunc')) {
                    this.fieldConfig[field].initFunc(this);
                }
            }
            this.pageInit = true;
        }
    }
};
</script>

<style lang="scss">
.wo-page-body {
    background-color: #fff;
    border-radius: uni-unit(10px);
}
</style>
